<?php
/**
 * 类说明 :
 * User: 刘明昆
 * Date: 2019-1-28
 * Time: 16:33
 */
header("Content-type: text/html; charset=utf-8");
require 'dbUtils.php';
require 'jsonMsg.php';

$action = $_GET['action'];
switch ($action) {
    case "add":
        //获取要添加的内容
        $title = $_POST['title'];
        $keywords = $_POST['keywords'];
        $autor = $_POST['autor'];
        $content = $_POST['content'];

        //获取数据库实例
        $link = mysqlDB::getInstance();
        //执行添加操作
        $sql = "insert into admin(title,keywords,autor,addtime,content) values('$title','$keywords'
        ,'$autor',(SELECT sysdate()),'$content');";
        //执行sql
        $result = $link->query($sql);
        // 如果影响行数>=1,则判断添加成功,否则失败
        if ($result >= 1) {
            //    return msgtxt(200,"添加成功");
            return showmsgtxt(200);
        } else {
            //    return msgtxt(500,"添加失败");
            return showmsgtxt(500);
        }
        break;

    case "update":
        //获取要修改的内容
        $title = $_POST['title'];
        $keywords = $_POST['keywords'];
        $autor = $_POST['autor'];
        $content = $_POST['content'];
        $id = $_POST['id'];

        //获取数据库实例
        $link = mysqlDB::getInstance();
        //执行添加操作
        $sql = "update admin set title='$title',keywords='$keywords',autor='$autor',content='$content' where id='$id'";
        //执行sql
        $result = $link->query($sql);
        // 如果影响行数>=1,则判断添加成功,否则失败
        if ($result >= 1) {
            //    return msgtxt(200,"添加成功");
            return showmsgtxt(200);
        } else {
            //    return msgtxt(500,"添加失败");
            return showmsgtxt(500);
        }
        break;


    case "delete";

        $id = $_POST['id'];
        //获取数据库实例
        $link = mysqlDB::getInstance();
        //执行添加操作
        $sql = "delete from admin where id in ($id);";
        //执行sql
        $result = $link->query($sql);
        // 如果影响行数>=1,则判断添加成功,否则失败
        if ($result >= 1) {
            //    return msgtxt(200,"添加成功");
            return showmsgtxt(200);
        } else {
            //    return msgtxt(500,"添加失败");
            return showmsgtxt(500);
        }
        break;

}


